/**
 * 
 */
package com.demo2do.boyle.common.entity.advertisement;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.boyle.common.entity.aduser.Aduser;
import com.demo2do.boyle.common.entity.aduser.material.Material;
import com.demo2do.boyle.common.entity.customer.social.SocialType;
import com.demo2do.boyle.common.entity.task.Task;

/**
 * 
 * 任务投放表
 * 
 * @author Leo
 */
@Entity
@Table(name = "advertisement")
public class Advertisement {
	
	@Id
	@GeneratedValue
	private Integer id;
	
	/** 投放标题 */
	@Column(name = "title")
	private String adTitle;
	
	@ManyToOne(optional = false, fetch = FetchType.LAZY)
	private Aduser aduser; 
	
	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	private Material material;
	
	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @Fetch(FetchMode.SELECT)
    @PrimaryKeyJoinColumn
    @JSONField(serialize = false)
	private AdvertisementTag advertisementTag;
	
	/** 品牌Id[冗余] */
	private int brandId;
	
	/** 投放创建时间 */
	private Date createDate;
	
	/** 投放开始时间 -- 审核通过 即开始 */
	private Date startDate;
	
	/** 投放结束时间*/
	private Date endDate;
	
	/** 投放平台 */
	@Enumerated(EnumType.ORDINAL)
	private SocialType socialType;
	
	/** 投放类型:投放量／预算制 */
	@Enumerated(EnumType.ORDINAL)
	private PutType type;
	
	/** 投放量值 */
	private Integer putNumber;
	
	/** 已认领值 */
	private int claimNumber;

	/** 新建投放步骤 */
	private Integer step;
	
	@Enumerated(EnumType.ORDINAL)
	private Status status;
	
	/** 审核人 */
	private String auditor;
	
	@Transient
	private List<Task> tasks;
	
	/**
	 * The Default constructor
	 */
	public Advertisement() {
		
	}
	
	/**
	 * pass advertisement : set status and set auditor
	 * 
	 * @return
	 */
	public Advertisement pass(String auditor) {
		this.status = Status.UNPAY;
		this.auditor = auditor;
		return this;
	}
	
	/**
	 * unpass advertisement : set status and set auditor
	 * 
	 * @return
	 */
	public Advertisement unpass(String auditor) {
		this.step = 0;
		this.status = Status.UNPASS;
		this.auditor = auditor;
		return this;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @return the adTitle
	 */
	public String getAdTitle() {
		return adTitle;
	}

	/**
	 * @return the aduser
	 */
	public Aduser getAduser() {
		return aduser;
	}

	/**
	 * @return the material
	 */
	public Material getMaterial() {
		return material;
	}

	/**
	 * @return the advertisementTag
	 */
	public AdvertisementTag getAdvertisementTag() {
		return advertisementTag;
	}

	/**
	 * @return the brandId
	 */
	public int getBrandId() {
		return brandId;
	}
	
	/**
	 * 
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @return the SocialType
	 */
	public SocialType getSocialType() {
		return socialType;
	}

	/**
	 * @return the type
	 */
	public PutType getType() {
		return type;
	}

	/**
	 * @return the putNumber
	 */
	public Integer getPutNumber() {
		return putNumber;
	}
	
	/**
	 * 
	 * @return the claimNumber
	 */
	public int getClaimNumber() {
		return claimNumber;
	}

	/**
	 * @return the step
	 */
	public Integer getStep() {
		return step;
	}

	/**
	 * @return the status
	 */
	public Status getStatus() {
		return status;
	}

	/**
	 * @return the auditor
	 */
	public String getAuditor() {
		return auditor;
	}

	/**
	 * @return the tasks
	 */
	public List<Task> getTasks() {
		return tasks;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param adTitle the adTitle to set
	 */
	public void setAdTitle(String adTitle) {
		this.adTitle = adTitle;
	}

	/**
	 * @param aduser the aduser to set
	 */
	public void setAduser(Aduser aduser) {
		this.aduser = aduser;
	}

	/**
	 * @param material the material to set
	 */
	public void setMaterial(Material material) {
		this.material = material;
	}

	/**
	 * @param advertisementTag the advertisementTag to set
	 */
	public void setAdvertisementTag(AdvertisementTag advertisementTag) {
		this.advertisementTag = advertisementTag;
	}

	/**
	 * @param brandId the brandId to set
	 */
	public void setBrandId(int brandId) {
		this.brandId = brandId;
	}
	
	/**
	 * 
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @param socialType the socialType to set
	 */
	public void setSocialType(SocialType socialType) {
		this.socialType = socialType;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(PutType type) {
		this.type = type;
	}

	/**
	 * @param putNumber the putNumber to set
	 */
	public void setPutNumber(Integer putNumber) {
		this.putNumber = putNumber;
	}
	
	/**
	 * 
	 * @param claimNumber the claimNumber to set
	 */
	public void setClaimNumber(int claimNumber) {
		this.claimNumber = claimNumber;
	}

	/**
	 * @param step the step to set
	 */
	public void setStep(Integer step) {
		this.step = step;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(Status status) {
		this.status = status;
	}

	/**
	 * @param auditor the auditor to set
	 */
	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	/**
	 * @param tasks the tasks to set
	 */
	public void setTasks(List<Task> tasks) {
		this.tasks = tasks;
	}
	
}
